﻿using System.Text;
using System.Windows;
//using SilverlightContrib.Xaml;

namespace Sonce.Common
{
    public class Converter
    {
        //Get the xaml element with child elements as xml string
        //public static string FrameworkElementToString(FrameworkElement element)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    XamlWriterSettings settings = new XamlWriterSettings();
        //    using (XamlWriter writer = XamlWriter.CreateWriter(sb, false, settings))
        //    {
        //        writer.WriteElement(element);
        //    }
        //    return sb.ToString();
        //}

        /// <summary>
        /// Measure shape position and dimensions and return Rect object. Coordinates are absolute to editor's origin.
        /// </summary>
        /// <param name="shape">FrameworkElement or any other inherited xaml element.</param>
        /// <returns>Rect object.</returns>
        public static Rect ShapeToRect(FrameworkElement shape)
        {
            double x1 = shape.Margin.Left;
            double y1 = shape.Margin.Top;
            double x2 = x1 + shape.Width;
            double y2 = y1 + shape.Height;
            return new Rect(new Point(x1, y1), new Point(x2, y2));
        }
    }
}
